package org.as.sdg.beans;

import java.io.Serializable;
import java.util.HashMap;

import org.as.sdg.objs.Node;

@SuppressWarnings("serial")
public class ApplicationSessionModel implements Serializable {

	// current node, and thus content the user is viewing
	private Node currentNode;

	// navigation tree model states
	private NavigationTreeFactory navigationTreeFactory;

	// navigation panel collapsible expanded state
	private NavigationPanelCollapsibleFactory navigationPanelCollapsible;

	// map of tab content visited by users, lazy loaded
	private HashMap<Node, TabState> tabContents;

	/**
	 * Creates a new instance of this class, instantiating the
	 * navigationTreeFactory and tabContents data models.
	 */
	public ApplicationSessionModel() {
		navigationTreeFactory = new NavigationTreeFactory();
		navigationPanelCollapsible = new NavigationPanelCollapsibleFactory();
		tabContents = new HashMap<Node, TabState>();
	}

	/**
	 * Gets the selected tabSet index for the currently selected node.
	 * 
	 * @return selected tabset for the currently selected node.
	 */
	public int getSelectedTabIndex() {
		// get the tabset state for this example
		TabState tabState = tabContents.get(currentNode);
		return tabState.getTabIndex();
	}

	/**
	 * Sets the selected tab index for the currently selected node tabState
	 * model.
	 * 
	 * @param tabIndex
	 *            tabIndex currently selected in a tabSet component.
	 */
	public void setSelectedTabIndex(int tabIndex) {
		TabState tabState = tabContents.get(currentNode);
		tabState.setTabIndex(tabIndex);
	}

	/**
	 * Gets the currently select node.
	 * 
	 * @return selected node
	 */
	public Node getCurrentNode() {
		return currentNode;
	}

	/**
	 * Sets the currently selected node.
	 * 
	 * @param currentNode
	 *            node to be set as the currently selected node.
	 */
	public void setCurrentNode(Node currentNode) {
		this.currentNode = currentNode;
	}

	/**
	 * Gets the navigation tree factory
	 * 
	 * @return navigation tree factory
	 */
	public NavigationTreeFactory getNavigationTrees() {
		return navigationTreeFactory;
	}

	/**
	 * Gets the navigation panelCollapsible factory
	 * 
	 * @return navigation panelCollapsible factory
	 */
	public NavigationPanelCollapsibleFactory getNavigationPanelCollapsible() {
		return navigationPanelCollapsible;
	}

	/**
	 * Gets the tabContents data model.
	 * 
	 * @return tab contents data model.
	 */
	public HashMap<Node, TabState> getTabContents() {
		return tabContents;
	}

	/**
	 * Gets the TabState model for the currently selected navigation node. .
	 * 
	 * @return TabState model for the selected Node.
	 */
	public TabState getSelectedTabState() {
		return tabContents.get(currentNode);
	}
}
